import {reactive} from "vue";
import Buff from "@/modal/Buff";

const buff = reactive(Buff.getInstance());
export default class Goods {
  readonly capacity: number = 120;
  private currentQuantity_: number = 0;
  private peachQuantity_: number = 0;
  private blackberryQuantity_: number = 0;
  private appleQuantity_: number = 0;
  private barrowQuantity_: number = 0;
  private getBonusTimes_: number = 0;

  get currentQuantity() {
    return this.currentQuantity_ +
      this.peachQuantity_ +
      this.blackberryQuantity_ +
      this.appleQuantity_ +
      this.barrowQuantity_
  }

  gainGoods(capacity: number) {
    this.currentQuantity_ += capacity;
    console.log(`当前货物:${this.currentQuantity}`)
  }

  // 是否触发奖励行动
  get isBonus() {
    return this.currentQuantity - this.bonusTimes * 5 >= 5
  }

  private get bonusTimes() {return this.getBonusTimes_;}

  // 兑现奖励行动
  getBonus() {
    if (this.isBonus) this.getBonusTimes_++;
  }

  // 苹果换货物
  public appleSwitchGoods() {
    this.appleQuantity_ += buff.appleGoods;
    console.log(`苹果货物:${this.appleQuantity_}`);
  }

  // 桃子换货物
  public peachSwitchGoods() {
    this.peachQuantity_ += buff.peachGoods;
    console.log(`桃子货物:${this.peachQuantity_}`);
  }

  // 黑莓换货物
  public blackberrySwitchGoods() {
    this.blackberryQuantity_ += buff.blackberryGoods;
    console.log(`黑莓货物:${this.blackberryQuantity_}`);
  }

  // 工具棚换货物
  public barrowSwitchGoods() {
    this.barrowQuantity_ += buff.barrowGoods;
  }

  // 单例模式
  private constructor() {
  }

  private static instance: Goods | null = null;

  public static getInstance(): Goods {
    if (this.instance === null) {
      this.instance = new Goods();
    }
    return this.instance
  }
}